<style lang="less" scoped>
.item {
  background: #f8f8f8;
  border-radius: 4px;
  padding: 5px;
  display: flex;
  align-items: center;
  border: 0.1px solid #eaeaea;
  overflow: hidden;
  height: 50px;

  &__avator {
    width: 40px;
    font-size: 14px;
  }
  &__content {
    font-size: 12px;
    color: #666;
    padding-left: 5px;
    &-title {
      width: 110px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      word-break: break-all;
    }
  }
}
</style>

<template>
    <!-- 股东 -->
    <div class="item" v-if="item.StockName" @click="itemClick">
        <div class="item__avator avator">
            <image class="avator-img" v-if="item.ImageUrl" :src="item.ImageUrl" />
            <text-to-avator v-else :text="item.StockName"></text-to-avator>
        </div>
        <div class="item__content">
            <div class="item__content-title c-primary">{{item.StockName||'-'}}</div>
            <div class="item__content-txt">持股比例{{item.StockPercent||'-'}}</div>
            <div class="item__content-txt">投资企业{{item.CompanyCount||'-'}}家</div>
        </div>
    </div>
    <!-- 主要人员 -->
    <div class="item" v-else @click="itemClick">
        <div class="item__avator avator">
            <image class="avator-img" v-if="item.avatar" :src="item.avatar" />
            <text-to-avator v-else :text="item.Name"></text-to-avator>
        </div>
        <div class="item__content">
            <div class="item__content-title c-primary">{{item.Name||'-'}}</div>
            <div class="item__content-txt">关联企业{{item.CompanyCount||'-'}}家</div>
        </div>
    </div>
</template>
<script>
import TextToAvator from '@/components/textToAvator';

export default {
  props: ['item'],
  components: {
    TextToAvator
  },
  methods: {
    isFaren(KeyNo) {
      if (!KeyNo) {
        return false;
      }
      return KeyNo.indexOf('p') === 0;
    },
    itemClick() {
      const item = this.item;
      const isFaren = this.isFaren(item.KeyNo);
      if (isFaren) {
        // 法人
        const Oper = {
          Name: item.StockName || item.Name,
          KeyNo: item.KeyNo
        };
        this.$router.push({
          path: '/pages/base/faren/main',
          query: {
            Oper: JSON.stringify(Oper)
          }
        });
        return;
      }
      // 企业
      this.$router.push({
        path: '/pages/company/main',
        query: {
          unique: item.KeyNo
        }
      });
    }
  }
};
</script>

